<?php

namespace seecms;

use seecms\db\SeeDb;
use seecms\db\SeeDbConnection;
use seecms\db\SeeDbTable;
use seecms\lib\Provider;
use seecms\lib\Twig;

class See
{
    /**
     * @param $controller
     * @return mixed
     * @throws SeeException
     */
    public static function controller($controller)
    {

        if (class_exists($controller)) {
            return new $controller;
        }

        $controller = lcfirst($controller);
        $controllers = See::module()->getController();
        $class = $controllers[$controller] ?? '';
        if (empty($class)) {
            $class = '\seecms\controller\\' . $controller;
        }

        if (!class_exists($class)) {
            throw new SeeException($class . ' not exist');
        }

        return new $class;
    }

    /**
     * 获取缓存文件
     * @return SeeCache
     */
    public static function cache(): SeeCache
    {
        return SeeCache::instance();
    }

    /**
     * 获取配置文件
     * @return SeeConfig
     */
    public static function config(): SeeConfig
    {
        return SeeConfig::instance();
    }

    /**
     * 获取参数
     * @return SeeRequest
     */
    public static function request(): SeeRequest
    {
        return SeeRequest::instance();
    }

    /**
     * 获取服务
     * @return Provider
     */
    public static function provider(): Provider
    {
        return new Provider();
    }

    /**
     * 获取模型实例
     */
    public static function db(): SeeDbConnection
    {
        return SeeDb::connect();
    }

    /**
     * @return SeeDbTable
     */
    public static function table(): SeeDbTable
    {
        return new SeeDbTable();
    }

    /**
     * @return SeeLang
     */
    public static function lang(): SeeLang
    {
        return SeeLang::instance();
    }

    /**
     * @return SeeView
     */
    public static function view(): SeeView
    {
        return new SeeView();
    }

    /**
     * @return Twig
     */
    public static function twig(): Twig
    {
        return Twig::instance();
    }

    /**
     * @return SeeModule
     */
    public static function module(): SeeModule
    {
        return SeeModule::instance();
    }
}